package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.dm.DmHistory
import com.cheyun.netsalev3.utils.api.*
import com.cheyun.netsalev3.utils.api.dm.DmApiCallback
import com.cheyun.netsalev3.utils.api.dm.DmApiException
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlin.reflect.KFunction1

class DmCallRecordRepository(var id:Int):BaseRepository() {
    //获取通话记录
    fun getData(kFunction1: KFunction1<@ParameterName(name = "item") List<DmHistory>, Unit>) {
        networkState.postValue(NetworkState.LOADING)
        DmApiClient.getInstance().getCallphoneList(id)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : DmApiCallback<DmBaseResp<List<DmHistory>,Any>>() {
                    override fun onSuccess(t: DmBaseResp<List<DmHistory>,Any>) {
                        networkState.postValue(NetworkState.LOADED)
                        t.list?.apply {
                            kFunction1(this)
                        }
                    }

                    override fun onError(ex: DmApiException) {
                        networkState.postValue(NetworkState.error(ex.getMessage()))
                    }
                })
    }
}